#include "Col.ph"
#ifdef __GNUG__
#pragma implementation
#endif

#include "Date.h"

#include "Math.h"
#include "Class.h"
#include "String.h"
#include "ET_stdio.h"

//---- Date --------------------------------------------------------------------

Date::Date(long s, long ms)
{
	sec= s;
if (s > 0) {
	if (ms >= 1000) {
		sec+= ms / 1000;
		msec= ms % 1000;
	} else if (ms < 0) {
		sec-= -ms / 1000;
		msec= -ms % 1000;
	} else
		msec= ms;
} else {
	if (ms <= -1000) {
		sec-= -ms / 1000;
		msec= -ms % 1000;
	} else if (ms > 0) {
		sec+= ms / 1000;
		msec= ms % 1000;
	} else
		msec= ms;
}
}

const char *Date::AsString() const
{
	return form("%d.%d", sec, msec);
}

OStream &operator<< (OStream &os, const Date &d)
{
	return os << d.sec SP << d.msec SP;
}

IStream &operator>> (IStream &is, Date &d)
{
	return is >> d.sec >> d.msec;
}

SimpleMetaImpl(Date)
{
	len= len;
	isptr= isptr;
	sprintf(buf, "%s", ((Date*) addr)->AsString());
}

